<?php 
header("Content-Type: text/html; charset=ISO-8859-1",true);
if(!isset($_SESSION))session_start();
if(!isset($_SESSION['usuario'])){
	session_destroy();
	header("location:index.php"); exit;
	}

//include 'classes/crud.php';
include 'classes/classeCCP.php';
/*
$funcionario=$_POST['funcionario'];
$setor=$_POST['setor'];
$funcao=$_POST['funcao'];
$turno=$_POST['turno'];
$values=array('', $_POST['funcionario'], $setor, $funcao, $turno);
if ($funcionario=='' || $setor=="" || $funcao=="" || $turno== ""){
print "<script>alert('Preencha todos os campos');</script>";
}else{
$con->insert("funcionario", $values);
$con->select("funcionario", $rows="*", $where="nome='$funcionario'");
if ($con->getResult()== TRUE)
echo "<script> alert('Adicionado com sucesso');</script>";	
} 
*/
$ccp = new classeCCP($_SESSION['setor']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="js/jscript.js"></script>
<title>Criar Pasta ou Setor</title>
<style type="text/css">
#fundo {
	position:relative;
	width:230px;
	height:230px;
	z-index:1;
	padding: 0;
	background-color: #FFF;
	margin: auto;
}

#area{
	position:absolute;
	width:230px;
	height:230px;
	left: -115px;
	top: -115px;
	margin-left: 50%;
	margin-top: 50%;
}
body,td,th {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 10px;
	color: #000;
}
body {
	background-color: #000;
}
#link {
	position: absolute;
	left: 79px;
	top: 218px;
	text-decoration: none;
	color: #000;
	cursor: pointer;
}
#link a {
	color: #000;
	text-decoration: none;
}
a:hover {
	font-size: 12px;
	color: #000;
	text-decoration: none;
	font-weight: bold;
}
</style>
<script type="text/javascript" src="js/jquery-1.5.1.js"></script>

</head>

<body>
<script type="text/javascript">
$(function(){
		setSubPasta();
		
		$('select[name=tipo]').change(function(){
			if ($(this).val() != 'Nova Empresa'){
			$('#set').show();
			$('#sub').show();
			$('#info').show();
			}else{
			$('#set').hide();
			$('#sub').hide();
			$('#info').hide();
			}
		})
	
	})
</script>
<div id="fundo">
<div id="area">
  <form id="form1" name="form1" method="post" action="criarp.php?acao=criar">
    <p><center>
      <label for="Nome da Pasta"></label>
      Nome da Empresa/Pasta<br />
      <input type="text" name="nome" />
    </center></p>
    <p><center>
    Tipo<br />
      <label for="select"></label>
      <select name="tipo" id="select">
        <option>Pasta de Arquivos</option>
     <?php
	 if ($_SESSION['grupo'] == 'Administrador')
	    echo "<option>Nova Empresa</option>";
	  ?>
        <option>Subpasta</option>
      
	  </select>
    
    </center></p>
    <p><center>
    <span id="info">Para pastas escolha a empresa</span><br />
    <?php 
	$con= new Crud();
$con->connect();
//## setando bd de teste ##
//$con->setDatabase('test');
	
	
	$sql = mysql_query("select * from categorias where heranca=0 ");
	echo '<select name=setor id=set>';
	while($result = mysql_fetch_array($sql)){

	echo "<option>$result[nome]</option>";
		}
		
	?>
    </select>
	<br />
	<select name="subpasta" id="sub">
   
	</select>
      <br /> 
	   <?php
        if ($_SESSION['grupo'] == 'Administrador'){
			$con= new Crud();
$con->connect();
			$sqlrep = mysql_query("select * from setor");
			echo '<select name="rep" id="rep">';
			echo "<option>Escolha o setor</option>";
			while ($repn=mysql_fetch_array($sqlrep)){
				$reparticao = $repn['setor_nome'];
				echo "<option>$reparticao</option>";
				}
			echo "</select>";
			}
	   ?>
        </center></p>
    
    <p><center>
      <script type="text/javascript">setValor();</script>
      <input type="hidden" name="ccp" value="criarp" />
      <input type="submit" name="submit" id="button" value="Criar" />
    </center></p>
  </form>
</div>
<center><div id="link"><a href=# onclick="window.close()";>Fechar Janela</a></div></center>
</div>
<script language="javascript">window.opener.location.reload();</script>
</body>
</html>
<?php
if ($_GET[acao] == 'criar'){
$ccp->criarPasta();
var_dump($ccp);
}
?>
